<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/17 0017
 * Time: 下午 9:01
 */

namespace App\Services;


use App\Base\BaseController;
use App\Model\LazyCommon\WechatModel;
use Symfony\Component\HttpFoundation\Request;

class JsApiParam
{
    public $JsApiParam;
    public $doctrine;
    public function __construct($doctrine)
    {
        $this->doctine = $doctrine;
    }

    public function getP()
    {
//        $request = Request::createFromGlobals();
//        $WechatModel = new WechatModel($this->doctine);
//        $WechatModel->getAccessToken();
//        $WechatModel->getJsApiTicket();
//        //微信分享签名
//        $now = time();
//        $JsApiParam["appId"] = $WechatModel->AppId;
//        $JsApiParam["timestamp"] = $now;
//        $JsApiParam["noncestr"] = sha1($now);
//        $JsApiParam["url"] = $request->getUri();
//
//        $jsapi_ticket = $WechatModel->JsApiTicket;
//        $timestamp = $JsApiParam["timestamp"];
//        $noncestr = $JsApiParam["noncestr"];
//        $url = $JsApiParam["url"];
//        $signature =  sha1("jsapi_ticket=$jsapi_ticket&noncestr=$noncestr&timestamp=$timestamp&url=$url");
//
//        $JsApiParam["signature"] = $signature;
//        $JsApiParam["url"] = $request->getUri();
//        $JsApiParam["ticket"] = $WechatModel->JsApiTicket;
//        $JsApiParam["str1"] = "jsapi_ticket=$jsapi_ticket&noncestr=$noncestr&timestamp=$timestamp&url=$url";
//        return $JsApiParam;
    }

    /**
     * 	作用：产生随机字符串，不长于32位
     */
    public function createNoncestr( $length = 32 )
    {
        $chars = "abcdefghijklmnopqrstuvwxyz0123456789";
        $str ="";
        for ( $i = 0; $i < $length; $i++ )  {
            $str.= substr($chars, mt_rand(0, strlen($chars)-1), 1);
        }
        return $str;
    }
}